//
//  EDSMySelfBadgeButton.m
//  DrivieSchoolStudents
//
//  Created by TangBin on 2019/6/4.
//  Copyright © 2019 班文政. All rights reserved.
//

#import "EDSMySelfBadgeButton.h"

@interface EDSMySelfBadgeButton ()
@property (nonatomic, strong) UILabel *badgeLabel;

- (void)initWithBadgeLabel;
@end

@implementation EDSMySelfBadgeButton

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self initWithBadgeLabel];
    }
    return self;
}

- (void)initWithBadgeLabel
{
    if (!_badgeLabel)
    {
        CGRect frame = CGRectMake(0, 0, 17, 17);
        _badgeLabel = [[UILabel alloc] initWithFrame:frame];
        _badgeLabel.backgroundColor = [UIColor colorWithHexString:@"#F23D3D"];
        _badgeLabel.font = [UIFont systemFontOfSize:10];
        _badgeLabel.textColor = [UIColor whiteColor];
        _badgeLabel.layer.shadowColor = [UIColor colorWithRed:242/255.0 green:61/255.0 blue:61/255.0 alpha:0.3].CGColor;
        _badgeLabel.layer.shadowOffset = CGSizeMake(0,1);
        _badgeLabel.layer.shadowOpacity = 1;
        _badgeLabel.layer.shadowRadius = 2;
        _badgeLabel.layer.masksToBounds = YES;
        _badgeLabel.layer.borderColor = [UIColor whiteColor].CGColor;
        _badgeLabel.layer.borderWidth = 1;
        _badgeLabel.layer.cornerRadius = 17 * 0.5;
        _badgeLabel.center = CGPointMake(self.width - 2, frame.size.height * 0.5);
        _badgeLabel.text = @"0";
        _badgeLabel.textAlignment = NSTextAlignmentCenter;
        _badgeLabel.hidden = YES;
        [self addSubview:_badgeLabel];
        _badgeLabel.center = CGPointMake(self.width - 2, frame.size.height * 0.5);
    }
}

- (void)updateBadgeImage:(BOOL)isImg
{
    CGRect frame = CGRectMake(0, 0, 17, 17);
    if (isImg)
    {
        _badgeLabel.center = CGPointMake(self.width - 6, frame.size.height * 0.5);
    }
    else
    {
        _badgeLabel.center = CGPointMake(self.width - 2, frame.size.height * 0.5);
    }
}

/**
 提示数量
 
 @param num num description
 */
- (void)updateTipBadgeNum:(NSInteger)num
{
    _badgeLabel.hidden = NO;
    if (num == 0)
    {
        _badgeLabel.hidden = YES;
    }
    else if (num > 99)
    {
        _badgeLabel.text = @"99";
    }
    else
    {
        _badgeLabel.text = [NSString stringWithFormat:@"%d", (int)num];
    }
}

@end

